package com.hjc.springbootmovies.intercaptors.config;

import com.hjc.springbootmovies.intercaptors.AdminHandler;
import com.hjc.springbootmovies.intercaptors.UserHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/12/4
 * Time: 16:50
 * To change this template use File | Settings | File Templates.
 */
@Configuration
public class UserIntercaptor implements WebMvcConfigurer {

    @Autowired
    UserHandler userHandler;
    @Autowired
    AdminHandler adminHandler;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns("/**") 表示拦截所有的请求，
        // excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
        registry.addInterceptor(userHandler).addPathPatterns("/**")
                .excludePathPatterns("/","/users/usersInfo","logout","/js/**","/images/**","/css/**","fonts/**");
        registry.addInterceptor(adminHandler).addPathPatterns("/emp/empControllerAll");
    }
}
